package org.vsg.security.model.service.impl;

import java.io.Serializable;
import java.util.Collection;

import org.vsg.common.biz.exception.ServiceException;
import org.vsg.common.pagination.Pagination;
import org.vsg.common.pagination.PaginationException;
import org.vsg.common.pagination.carrier.Carrier;
import org.vsg.common.pagination.carrier.RecordLimitCarrier;
import org.vsg.common.pagination.datatrans.PaginationProvider;
import org.vsg.common.pagination.datatrans.PaginationProviderFactory;
import org.vsg.security.model.domain.ResourceAssociation;
import org.vsg.security.model.persistence.ResourceAssociationDao;
import org.vsg.security.model.service.ResourceAssociationService;


public class ResourceAssociationServiceImpl implements ResourceAssociationService {
	/**
	 * set the pagination provider factory
	 * 
	 * 
	 */
	private PaginationProviderFactory factory = PaginationProviderFactory
			.getInstance();

	private ResourceAssociationDao resourceAssociationDao;

	/**
	 * @param carrier
	 * @return
	 * @exception ServiceException
	 * @exception PaginationException
	 */
	public Pagination pageSysPermission(Carrier carrier) throws ServiceException,
			PaginationException {
		// TODO: implement
		PaginationProvider provider = factory
				.generateProvider((RecordLimitCarrier) carrier);
		return resourceAssociationDao.pageSysPermission(provider);
	}

	/**
	 * @param carrier
	 * @return
	 * @throws ServiceException
	 * @exception PaginationException
	 */
	public Pagination pageSysPermissionByAll(Carrier carrier) throws ServiceException,
			PaginationException {
		// TODO: implement
		PaginationProvider provider = factory
				.generateProvider((RecordLimitCarrier) carrier);
		return resourceAssociationDao.pageSysPermissionByAll(provider);
	}
	
	@Override
	public void saveAll(Collection<ResourceAssociation> all)
			throws ServiceException {
		// TODO Auto-generated method stub
		resourceAssociationDao.saveAll(all);
		
	}  	

	/**
	 * @param sysPermission
	 * @exception ServiceException
	 */
	public void addSysPermission(ResourceAssociation sysPermission) throws ServiceException {
		// TODO: implement
		resourceAssociationDao.save(sysPermission);
	}

	/**
	 * @param sysPermission
	 * @exception ServiceException
	 */
	public void updateSysPermission(ResourceAssociation sysPermission) throws ServiceException {
		// TODO: implement
		resourceAssociationDao.update(sysPermission);
	}

	/**
	 * @param sysPermission
	 * @exception ServiceException
	 */
	public void updateSimpleSysPermission(ResourceAssociation newEntity) throws ServiceException {
		// TODO: implement
		ResourceAssociation original = resourceAssociationDao.load( newEntity.getId() );
		
		original.setId( newEntity.getId()  );
		
		// --- update the method ---
		resourceAssociationDao.update( original );		
		
	}

	/**
	 * @param sysPermission
	 * @exception ServiceException
	 */
	public void deleteSysPermission(ResourceAssociation sysPermission) throws ServiceException {
		// TODO: implement
		resourceAssociationDao.delete(sysPermission);
	}

	@Override
	public void deleteAll(Collection<ResourceAssociation> all)
			throws ServiceException {
		// TODO Auto-generated method stub
		resourceAssociationDao.deleteAll(all);
	}
	

	/**
	 * @param pk
	 * @exception ServiceException
	 */
	public ResourceAssociation loadSysPermission(Serializable pk) throws ServiceException {
		// TODO: implement
		return resourceAssociationDao.load(pk);
	}


	@Override
	public Collection<ResourceAssociation> findByAll() throws ServiceException {
		// TODO Auto-generated method stub
		return resourceAssociationDao.findByAll();
	}


	public ResourceAssociationDao getResourceAssociationDao() {
		return resourceAssociationDao;
	}

	/**
	 * @param newSysPermissionDao
	 */
	public void setResourceAssociationDao(ResourceAssociationDao newSysPermissionDao) {
		resourceAssociationDao = newSysPermissionDao;
	}




}